package com.example.springsecurity.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springsecurity.common.annotation.SystemLogInterface;
import com.example.springsecurity.common.enums.BusinessTypeEnum;
import com.example.springsecurity.common.resp.ResponseResult;
import com.example.springsecurity.entity.SystemRole;
import com.example.springsecurity.service.SystemRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

import static com.example.springsecurity.common.resp.ResponseResult.success;

/**
 * 角色信息表(SystemRole)表控制层
 *
 * @author aman
 * @since 2025-01-15 16:58:54
 */
@Tag(name = "系统角色管理")
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SystemRoleService systemRoleService;

    /**
     * 分页查询角色列表
     *
     * @param page       分页对象
     * @param systemRole 查询实体
     * @return 所有数据
     */
    @Operation(summary = "分页查询角色列表")
    @PostMapping("/queryRoleList")
    @SystemLogInterface(title = "分页查询角色列表", businessType = BusinessTypeEnum.QUERY)
    public ResponseResult<IPage<SystemRole>> queryRoleList(Page<SystemRole> page, SystemRole systemRole) {
        return success(this.systemRoleService.page(page, new QueryWrapper<>(systemRole)));
    }

    /**
     * 添加角色信息
     *
     * @param systemRole 实体对象
     * @return 新增结果
     */
    @Operation(summary = "添加角色信息")
    @PostMapping("/insertRole")
    @SystemLogInterface(title = "添加角色信息", businessType = BusinessTypeEnum.INSERT)
    public ResponseResult<Boolean> insertRole(@RequestBody SystemRole systemRole) {
        return success(this.systemRoleService.save(systemRole));
    }

    /**
     * 更新角色信息
     *
     * @param systemRole 实体对象
     * @return 修改结果
     */
    @Operation(summary = "更新角色信息")
    @PostMapping("/updateRole")
    @SystemLogInterface(title = "更新角色信息", businessType = BusinessTypeEnum.UPDATE)
    public ResponseResult<Boolean> updateRole(@RequestBody SystemRole systemRole) {
        return success(this.systemRoleService.updateById(systemRole));
    }

    /**
     * 删除角色信息
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @Operation(summary = "删除角色信息")
    @PostMapping("/deleteRole")
    @SystemLogInterface(title = "删除角色信息", businessType = BusinessTypeEnum.DELETE)
    public ResponseResult<Boolean> deleteRole(@RequestBody List<String> idList) {
        return success(this.systemRoleService.removeByIds(idList));
    }
}
